<template>
    <!-- 表单列表 -->
          <div>
            <el-row>
                <el-col :span="12" align="left">
                  <el-select v-model="selectTrialArr" multiple placeholder="请选择可试算产品">
                    <el-option
                      v-for="item in trialArr"
                      :key="item.productId"
                      :label="item.productName"
                      :value="item.productId">
                    </el-option>
                  </el-select>
                  <el-button type="primary" @click="search" :disabled="selectTrialArr.length==0" 
                  :loading="searchLoading" icon="el-icon-search">搜索</el-button>
                </el-col>
                <el-col :span="4"></el-col>
                <el-col :span="8" align="right">
                    <el-button type="success" @click="exports" :disabled="exportLoading" :loading="exportLoading">导出试算汇总数据</el-button>
                </el-col>
            </el-row>
            <el-row>
              <div class="fw">按日期</div>
              <el-table
                :data="table1"
                border
                stripe 
                size="mini"
                style="width:1051px;margin:20px auto;">
                <el-table-column
                  label="试算日期"
                  prop="trailDate"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="项目"
                  prop="productName"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="合同数"
                  prop="contractNumbers"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="资产转让总价"
                  prop="totalAssets"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="预期收益率"
                  prop="returnRate"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="预计投资退出日（指定日期）"
                  prop="trialInvestmentExitTime"
                  align="center"
                  width="150">
                </el-table-column>
                <el-table-column
                  label="预计投资者收益"
                  prop="expectInvestmentIncome"
                  align="center"
                  width="150">
                </el-table-column>
                <el-table-column
                  label="预计本金及收益合计"
                  prop="expectTotalRevenue"
                  align="center"
                  width="150">
                </el-table-column>
              </el-table>
              <div class="fw">按天数</div>
              <el-table
                :data="table2"
                border
                stripe 
                size="mini"
                style="width:1051px;margin:20px auto;">
                <el-table-column
                  label="试算日期"
                  prop="trailDate"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="项目"
                  prop="productName"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="合同数"
                  prop="contractNumbers"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="资产转让总价"
                  prop="totalAssets"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="预期收益率"
                  prop="returnRate"
                  align="center"
                  width="120">
                </el-table-column>
                <el-table-column
                  label="预计投资退出日（天数）"
                  prop="trialInvestmentExitTime"
                  align="center"
                  width="150">
                </el-table-column>
                <el-table-column
                  label="预计投资者收益"
                  prop="expectInvestmentIncome"
                  align="center"
                  width="150">
                </el-table-column>
                <el-table-column
                  label="预计本金及收益合计"
                  prop="expectTotalRevenue"
                  align="center"
                  width="150">
                </el-table-column>
              </el-table>  
            </el-row>  
          </div>
</template>

<script>
var selectTrialArr=[];
export default {
    data() {
        return {
          exportLoading:false,
            selectTrialArr:[],
            trialArr:[],
            searchLoading:false,
            table1:[],
            table2:[],
            value:[],
        };
    },
    mounted(){
        this.initData();
    },
    methods:{
        initData(){
          this
          .postRequest("/api/report/trial_summary/get_trial_products", {
            
          })
          .then(resp => {  
            if (resp && resp.data.status == 200){
                console.log(resp)
                this.trialArr=resp.data.obj;
            }
          });
          
        },
        search(){
          this.searchLoading=true;
          selectTrialArr=[]
          for(let i=0;i<this.selectTrialArr.length;i++){
            selectTrialArr.push(this.selectTrialArr[i])
          }
          this
          .postRequest("/api/report/trial_summary/trai_summary_mg", {
            productIds:selectTrialArr
          })
          .then(resp => {
            this.searchLoading=false;  
            if (resp && resp.data.status == 200){
                if(resp.data.obj.trailTime.length!=0){
                  this.table1=resp.data.obj.trailTime   
                }else{
                  this.table1=[]   
                }
                if(resp.data.obj.trailDate.length!=0){
                  this.table2=resp.data.obj.trailDate
                }else{
                  this.table2=[] 
                }
            }
          });

        },
        exports(){
          this.exportLoading=true;
          console.log(selectTrialArr)
          var address='/api/report/trial_summary/trial_summary_export?productIds='+selectTrialArr
          this.common.downloadFile(address); 
          setTimeout(()=>{
            this.exportLoading=false;
          },2000)
        }
    }
}
</script>
<style scoped>
.el-row {
  margin-bottom: 30px;
  height: 50px;
  line-height: 50px;
}
.el-col {
  height: 50px;
  line-height: 50px;
}
</style>